import createVanilla from 'zustand/vanilla'
import { subscribeWithSelector } from 'zustand/middleware'
import create from 'zustand'
import { defaultData } from '@/api/manager/mtVmp/interface'
import { Mt } from '@/api/manager/mt'
import { Vmp } from '@/api/manager/vmp/interface'

export interface InitAutoVmpOption {
	/** 弹窗是否打开 */
	isOpen: boolean
	/** 终端自主多画面时信息 */
	mtInfo?: Mt
	mode: 'mtVmp' | 'setting'
	/** 数据 */
	data: Vmp
}
type VmpStore = InitAutoVmpOption & {
	update: (d: Partial<InitAutoVmpOption>) => void
	updateData: (d: Vmp | null) => void
	reset: () => void
	onInit: () => void
	onClose: () => void
	onConfirm: (data: Vmp) => void
	msgHandle: (data: any) => void
}
const initialState: InitAutoVmpOption = {
	isOpen: false,
	mode: 'setting',
	data: defaultData,
}
export const store = createVanilla<VmpStore>()(
	subscribeWithSelector((set, get) => ({
		...initialState,
		update: (d) => set({ ...d }),
		updateData: (data) => {
			let _data = data ?? defaultData
			set({ data: _data })
		},
		reset: () => set(initialState),
		onInit: () => {},
		onClose: () => {},
		onConfirm: (d) => {},
		msgHandle: (d) => {},
	}))
)
export const useAutoVmpStore = create(store)
